package show.lmm.oauth2.client.schedule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;

@Slf4j
@Component
public class UserInfoSchedule {
    private final WebClient webClient;

    public UserInfoSchedule(WebClient webClient) {
        this.webClient = webClient;
    }

    @Scheduled(cron = "0/2 * * * * ? ")
    public void query() {
        String result = this.webClient
                .get()
                .uri("http://127.0.0.1:8082/user_info/get?user_type=22")
                .attributes(ServletOAuth2AuthorizedClientExchangeFilterFunction.clientRegistrationId("messaging-client-model"))
                .retrieve()
                .bodyToMono(String.class)
                .block();
        log.info("Call resource server execution result: " + result);
    }
}
